<?php

namespace plugin\ssh\app\controller;

use app\common\util\YcLog;
use plugin\ssh\app\common\CustomSsh;

class TestController extends BaseController
{
    /**
     * @deprecated  ssh2方案不好用，需要安装扩展，有兼容性问题
     * @return \support\Response
     */
    public function testsshConnect()
    {
        YcLog::init("ssh");
        YcLog::debug("testsshConnect 开始");
        var_dump(date("Y-m-d H:i:s"));
        YcLog::debug("testsshConnect 结束");
        /**
         * 我的天翼云测试账号
         * IP：140.246.252.1
         * 账号：root
         * 密码：Lzj5002008
         */
        $result = ["a" => "bc"];
        $config = [
            'host' => '140.246.252.1',
            'port' => '22',
            'username' => "root",
            'password' => "Lzj5002008",
            'publicKey' => "",
            'privateKey' => "",
        ];
        $customSsh = new CustomSsh($config);
        //        $res = $customSsh->execute("cd /etc/proxy/proxy_admin/ && ls -la");
        $res = $customSsh->execute("top");
        $resArr = explode("\n", $res);
        $result["res"] = $res;
        $result["resArr"] = $resArr;

        return json($result);
    }
}
